package com.chenxin.interact.api;

import com.chenxin.common.annotation.InterfaceLogs;
import com.chenxin.common.constant.WmsConstants;
import com.chenxin.common.core.controller.BaseController;
import com.chenxin.common.core.domain.AjaxResult;
import com.chenxin.common.core.domain.ProcResult;
import com.chenxin.interact.domain.dto.*;
import com.chenxin.interact.process.ISapInteractProcess;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("sap/interact")
public class SapAPI extends BaseController {
    @Autowired
    private ISapInteractProcess sapInteractProcess;

    @InterfaceLogs(name = "SAP采购单传输接口")
    @PostMapping("/purchase")
    public AjaxResult sapPurchaseRequest(@RequestBody SapPurchaseReqDTO dto) {
        ProcResult result = sapInteractProcess.procSapPurchase(dto);
        if (WmsConstants.PROC_SUCCESS.equals(result.getCode())) {
            return success(result.getMessage());
        } else {
            return error(result.getMessage());
        }
    }

    @InterfaceLogs(name = "SRM送货单传输接口")
    @PostMapping("/deliver")
    public AjaxResult srmDeliverRequest(@RequestBody SrmDeliverReqDTO dto) {
        ProcResult result = sapInteractProcess.procSrmDeliver(dto);

        if (WmsConstants.PROC_SUCCESS.equals(result.getCode())) {
            return success(result.getMessage());
        } else {
            return error(result.getMessage());
        }
    }

    @InterfaceLogs(name = "SRM条码传输接口")
    @PostMapping("/barcode")
    public AjaxResult srmBarcodeRequest(@RequestBody SrmBarcodeReqDTO dto) {
        ProcResult result = sapInteractProcess.procSrmBarcode(dto);

        if (WmsConstants.PROC_SUCCESS.equals(result.getCode())) {
            return success(result.getMessage());
        } else {
            return error(result.getMessage());
        }
    }

    @InterfaceLogs(name = "SAP检验结果传输接口")
    @PostMapping("/quality")
    public AjaxResult sapQualityResult(@RequestBody SapQualityResultDTO dto) {
        ProcResult result = sapInteractProcess.procSapQuality(dto);
        if (WmsConstants.PROC_SUCCESS.equals(result.getCode())) {
            return success(result.getMessage());
        } else {
            return error(result.getMessage());
        }
    }

    @InterfaceLogs(name = "SAP销售单传输接口")
    @PostMapping("/sales")
    public AjaxResult sapSalesRequest(@RequestBody SapSalesReqDTO dto) {
        AjaxResult ajaxResult = AjaxResult.success(0, "success!");
        log.info("销售订单下发：{}", dto);
        return ajaxResult;
    }

    @InterfaceLogs(name = "SAP其他单据传输接口")
    @PostMapping("/others")
    public AjaxResult sapOthersRequest(@RequestBody SapSalesReqDTO dto) {
        AjaxResult ajaxResult = AjaxResult.success(0, "success!");
        log.info("其他单据下发：{}", dto);
        return ajaxResult;
    }
}
